package cn.com.dhc.danlu.fragment.base;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.umeng.analytics.MobclickAgent;

import cn.com.dhc.danlu.util.AgentUtils;

/**
 * User: Geek_Soledad(wuhaiyang@danlu.com)
 * Date: 2016-08-05
 * Time: 20:56
 * Description: .....
 */
public abstract class BaseV4Fragment extends Fragment {
    private static final String STATE_SAVE_IS_HIDDEN = "STATE_SAVE_IS_HIDDEN";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null) {
            //防止重叠发生
            boolean isSupportHidden = savedInstanceState.getBoolean(STATE_SAVE_IS_HIDDEN);
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            if (isSupportHidden) {
                ft.hide(this);
            } else {
                ft.show(this);
            }
            ft.commit();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(AgentUtils.getPackageInfo(getActivity()).packageName);

    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putBoolean(STATE_SAVE_IS_HIDDEN, isHidden());
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(AgentUtils.getPackageInfo(getActivity()).packageName);
    }
}